<?php

/* 商品评价 comment */
class CommentModel extends BaseModel
{
    var $table  = 'comment';
    var $prikey = 'comment_id';
    var $_name  = 'comment'; 
    var $_relation = array(   
        // 评价与订单关联
        'has_order' => array(
            'model'         => 'order',
            'type'          => HAS_ONE, 
            'refer_key'     => 'order_id',          
            'foreign_key'     => 'order_id',
            'dependent'     => true
        ),
        // 评价与订单商品关联
        'has_ordergoods' => array(
            'model'         => 'ordergoods',
            'type'          => HAS_ONE, 
            'refer_key'     => 'goods_id',          
            'foreign_key'     => 'goods_id',
            'dependent'     => true
        ),
                
        // 一个评价只能属于一个商品
        'belongs_to_goods' => array(
            'model'         => 'goods',
            'type'          => BELONGS_TO,
            'foreign_key'   => 'goods_id',
            'reverse'       => 'has_comment',
        )
    ); 
    
    public function delete_cache($goods_id = 0)
    {
        $cache_server =& cache_server();
        $key = 'page_of_goods_comment_' . $goods_id;
        $cache_server->delete($key);
    }
}

?>